﻿
using System;

namespace Pisces
{
	/**
	 * 游戏框架层的对象容器
     * created by wangqiang
    **/
	public class AbstractFrameworkEntityContainerModule : AbstractNormalModule
	{
		/**
		 * 逻辑对象容器
		 */
		private LogicEntityContainer logicEntityContainer;

		public override void onInit()
		{
			base.onInit();

			logicEntityContainer = new LogicEntityContainer();
			logicEntityContainer.onInit();
		}

		public override void onAwake()
		{
			base.onAwake();
			
			logicEntityContainer.onAwake();
		}

		public override void onUpdate(float deltaTime)
		{
			base.onUpdate(deltaTime);
			
			logicEntityContainer.onUpdate(deltaTime);
		}

		/// <summary>
		/// 创建逻辑和显示对象
		/// </summary>
		/// <param name="type"></param>
		/// <typeparam name="T"></typeparam>
		/// <returns></returns>
		public AbstractLogicEntity createEntity<T>(int type) where T : AbstractLogicEntity, new()
		{
			T logicEntity = logicEntityContainer.addEntity<T>();
			if (logicEntity == null)
			{
				return logicEntity;
			}
			
			return logicEntity;
		}
	}
	
}